<?php
namespace app\admin\controller;

class Link extends Base
{
	public $name='link';
    public function index()
    {
        $map=[];
		if(input('name')){
			$map[]=['name','like',"%".input('name')."%"];
		}
        $list = db($this->name)->where($map)->orderRaw("sort=0,sort,id")->paginate(20);
        $this->assign('list', $list);
        \cookie('url', \request()->url());
        return $this->fetch();
    }
    public function add()
    {
        if ($this->request->isAjax()) {
            $data['name']=input('name');
            $data['url']=input('url');
			$data['sort']=input('sort');
            $id=db($this->name)->insertGetId($data);
            $this->success("添加成功", cookie('url'));
        }
        return $this->fetch();
    }
   
    public function edit()
    {
        $map['id']=input('id');
        $vo = db($this->name)->where($map)->find();
        if ($this->request->isAjax()) {
            $data['name']=input('name');
            $data['url']=input('url');
            $data['sort']=input('sort');
            db($this->name)->where('id', $vo['id'])->update($data);
            $this->success("操作成功", cookie('url'));
        }
        $this->assign("vo", $vo);
        return $this->fetch();
    }
	
    public function dele()
    {
		$map['id']=input('id');
        db($this->name)->where($map)->delete();
        $this->success("操作成功",cookie('url'));
    }
}
